/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.util.FormUtil;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Adell
 */
public class FormHapusDosen extends JDialog {

    private JLabel nip;
    private JTextField tnip;
    private JButton hapus;

    public FormHapusDosen() {
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        this.setSize(250, 150);
        this.setTitle("Form Hapus Dosen");
        FormUtil.centerWindow(this);
        this.setLayout(null);

        nip = new JLabel("NIP ");
        nip.setBounds(20, 10, 100, 30);
        this.add(nip);

        tnip = new JTextField();
        tnip.setBounds(60, 10, 150, 25);
        this.add(tnip);

        hapus = new JButton("HAPUS");
        hapus.setBounds(70, 60, 100, 30);
        this.add(hapus);

        hapus.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                hapusDosenAction();
                if (e.getSource() == hapus) {
                    dispose();
                }
            }

            private void hapusDosenAction() {
                String hps = tnip.getText();

                Connection con = model.Conection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "sisil");
                Statement stat = null;
                try {
                    stat = con.createStatement();
                } catch (SQLException ex) {
                    Logger.getLogger(FormHapusDosen.class.getName()).log(Level.SEVERE, null, ex);
                }
                String sql = "delete from dosen where NIP = '" + hps + "'";
                try {
                    stat.executeUpdate(sql);
                    JOptionPane.showMessageDialog(null, "Dosen telah terhapus");
                } catch (SQLException ex) {
                    Logger.getLogger(FormHapusDosen.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });

        this.setVisible(true);
    }
}
